
# 李广龙
# nginx日志文件备份
# 现再logs文件夹下创建oldlogs文件夹
# 然后把脚本添加到linux定期任务中建议当天00:00点执行
# 0 0 * * *
# 再利用rsync进行日志远程备份
LOG_PATH=/usr/local/nginx/logs/oldlogs
CUR_LOG_PATH=/usr/local/nginx/logs
# 要保留的备份天数 #
backup_day=15
YESTERDAY=$(date +%F -d -1day)

find ${LOG_PATH} -type f -mtime +${backup_day} | xargs rm -rf

mv $CUR_LOG_PATH/access.log $LOG_PATH/${YESTERDAY}_access.log
mv $CUR_LOG_PATH/error.log $LOG_PATH/${YESTERDAY}_error.log
kill -USR1 $(cat /usr/local/nginx/logs/nginx.pid)